﻿@using QuestionsAnswers.UI.Models
@model List<Comment>

@{
    ViewBag.Title = "Index";
    AjaxOptions opts = new AjaxOptions {OnSuccess = "OnSuccessGeneral"};
}


<h2>
    Index</h2>
<p>
    @Ajax.ActionLink("Add Comment", "Create", new { id = @ViewBag.Answer.AnswerId },opts)
</p>
<p>
    @ViewBag.Answer.Text
</p>
<table>
    <tr>
         <th>
            Text
        </th>
        <th>
            User
        </th>
        <th>
        User Options
        </th>
        <th>
        </th>
    </tr>

@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Text)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.User.UserName)
        </td>
        <td>
            @Ajax.ActionLink("Edit", "Edit", new { id = item.CommentId },opts) |
            @Html.ConfirmLink("Delete","Comment", "Delete", new { id = item.CommentId },"Really Delete?")

             @*@Html.ActionLink("Comments", "Index", "Comment", new { id = item.CommentId }, "")*@
        </td>
    </tr>
    

@*    foreach (var comment in Model)
    {
        <tr>
        <td>
        @Html.Partial("RatingsPartial", new RateModel {Id = item.AnswerId,Type ="Answer",ReturnUrl = Request.Url.ToString()})
        </td>
            <td>
                @Html.DisplayFor(modelItem => item.Text)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.User.UserName)
            </td>
            <td>
            @Html.DisplayFor(modelItem=>item.AnswerRating)
            </td>
            @if (User.Identity.Name == item.User.UserName)
            {
                <td>
    <tr>
        <td>
            @Html.DisplayFor(modelcomment => item.Text)
           var comments = _db.Comments.Include(c => c.User).Include(c => c.Answer).Where(c => c.AnswerId == id);
        
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.User.UserName)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id = item.AnswerId }) |
            @Html.ActionLink("Delete", "Delete", new { id = item.AnswerId })

             @Html.ActionLink("Comments", "Index", "Comment", new { id = item.AnswerId }, "")
        </td>
       </tr>
                    @Html.ActionLink("Edit", "Edit", new { id = item.AnswerId })
                   |
                    @Html.ActionLink("Delete", "Delete", new { id = item.AnswerId })
                </td>
            }
        </tr>
    }
    *@
   

   
}

</table>
